package com.itheima.controller;

import com.itheima.entity.Dish;
import com.itheima.entity.Setmeal;
import com.itheima.jsonresult.JsonResult;
import com.itheima.service.DishService;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 新增套餐
     * @param setmeal
     * @return
     */
    @Transactional
    @PostMapping
    public JsonResult add(@RequestBody Setmeal setmeal){
        return setmealService.add(setmeal);
    }

    /**
     *修改套餐
     * @param setmeal
     * @return
     */
    @Transactional
    @PutMapping
    public JsonResult put(@RequestBody Setmeal setmeal){
        return setmealService.put(setmeal);
    }

    /**
     * 删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping
    public JsonResult delete(String ids) {
        return setmealService.delete(ids);
    }

    /**
     * 套餐分页查询
     * @param name
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public JsonResult getPage(String name, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize){
        return setmealService.getPage(name,page,pageSize);
    }

    /**
     * 套餐上架/下架
     * @param status
     * @param ids
     * @return
     */
    @PostMapping("/status/{status}")
    public JsonResult status(@PathVariable String status, String ids) {
        return setmealService.status(status,ids);
    }


    /**
     * 根据id查询套餐信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public JsonResult getDishById(@PathVariable String id) {
        return setmealService.getSetmealById(id);
    }





}
